
import post from './otherTool'
import config from "./config"
var WXTools = {
      getOpenId()  {

          var userInfo= wx.getStorageSync("userInfo");
          var jsCode= wx.getStorageSync("jscode");
           post("EHS/smallservice/OpenIdInfo/getOpenId.json", {
              jsCode:jsCode,
              encryptedData:userInfo.encryptedData,
              iv:userInfo.iv
           }).then(res => {
            console.log("获取Unlind777777==",res);
             if (res.data.returnCode == 1) {
             
                 wx.setStorageSync("unionid", res.data.unionid); //存储openid
                 wx.setStorageSync("openid", res.data.openId); //存储openid
             }else{
                 wx.setStorageSync("unionid", ""); //存储openid
                 wx.setStorageSync("openid", ""); //存储openid
             }
             wx.reLaunch({
              url: '../im/main',
            })
           });
    },

    getOpenIdiId()  {
      var userInfo= wx.getStorageSync("userInfo");
      var jsCode= wx.getStorageSync("jscode");
       post("EHS/smallservice/OpenIdInfo/getOpenId.json", {
          jsCode:jsCode,
          encryptedData:userInfo.encryptedData,
          iv:userInfo.iv
       }).then(res => {
        console.log("获取Unlind777777==",res);
         if (res.data.returnCode == 1) {
         
             wx.setStorageSync("unionid", res.data.unionid); //存储openid
             wx.setStorageSync("openid", res.data.openId); //存储openid
         }else{
             wx.setStorageSync("unionid", ""); //存储openid
             wx.setStorageSync("openid", ""); //存储openid
         }
       });
  },

     getWxLogin(){
       wx.login({
        success(res) {
          console.log("jscode====",res);
         if (res.code) {
           wx.setStorageSync("jscode", res.code); //存储openid
         } else {
            wx.setStorageSync("jscode", ""); //存储openid
         }
       }
      });
     },

 


      //获取定位
      getLocations() {
        wx.getLocation({
          type: "wgs84",
          success(res) {
            console.log("位置", res);
            wx.setStorageSync("currentPosition", ""); //存储openid
            let latitude = res.latitude;
            let longitude = res.longitude;
            let mapKey=config.mapKey;
            let url='https://apis.map.qq.com/ws/geocoder/v1/?location='+latitude+","+longitude+"&key="+mapKey;
            console.log("===666666666======",url)
            wx.request({
                      url: url,
                      success: res => {
                       console.log("===666666666======",res)
                        wx.setStorageSync("currentPosition", res); //存储openid
                      }
                    });
                 }
               });
             },



    //获取是否认证
    getIsFocus(){
      let unionid = wx.getStorageSync("unionid");
       post("EHS/smallservice/OpenIdInfo/checkAuthCar.json", {
       unionid: unionid 
     }).then(res => {
       console.log("获取关注绑定车辆信息");
       console.log(res);
       if (res.data.returnCode == 1) {
           wx.setStorageSync("isFocus", true); //存储openid
       } else {
           wx.setStorageSync("isFocus", false); //存储openid
           wx.showToast({
            title:res.data.returnMessage,
            icon: "none",
            duration: 3000
          });
       }
     });
   },


    //获取销售顾问是否在线
    getAdviserOnline(userID,remoteId){
      console.log("======获取是否在线数据1========",userID,remoteId);
       post("EHS/im/server/ImMainAction/isOnlineAndUnreadCount.json", {
        user_id: userID ,
        remote_user_id:remoteId
     }).then(res => {
       console.log("======获取是否在线数据2========",res);
       if (res.data.returnCode == 1) {
         var magCount=res.data.msgCount;
         if(magCount>99){
           magCount="99+"
         }
         var value={
          isOnline:res.data.isOnline,
          msgCount:magCount,
         }
            wx.setStorageSync("msgOnLineOrMsgNum", value); //存储openid
       } else {
        var value={
          isOnline:false,
          msgCount:0, 
         }
            wx.setStorageSync("msgOnLineOrMsgNum", value); //存储openid
       }
     });
   },


   isNull:function(obj){
    console.log('isNull判断obj是否为空====='+JSON.stringify(obj) )
    if (JSON.stringify(obj) === '[]' || ''|| "" === obj  || null === obj || JSON.stringify(obj) === '{}' || undefined === obj) {
      return true
    } else{
      return false
    }
   },


 }
 export default WXTools;